package com.hfi.controller;

import com.hfi.model.Employee;
import com.hfi.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author ChangLiang
 * @date 2019/5/30
 */
@Controller
@RequestMapping("/employee")
public class EmployeeGenerateController {

    @Autowired
    private IEmployeeService employeeService;

    @GetMapping("/getEmployeeById")
    @ResponseBody
    public Employee getEmployeeById(@RequestParam Integer id) {
        return employeeService.getById(id);
    }

    @GetMapping("/deleteAllEmployee")
    @ResponseBody
    public Integer deleteAllEmployee() {
        return employeeService.deleteAllEmployee();
    }

    @PostMapping("updateEmp")
    @ResponseBody
    public int updateEmp(@RequestBody Employee employee) {
        return employeeService.updateEmpByOptimisticLock(employee);
    }

    @GetMapping("/deleteAll")
    @ResponseBody
    public String deleteAll() {
        employeeService.deleteAll();
        return "success";
    }

    @GetMapping("deleteById")
    @ResponseBody
    public boolean deleteById(@RequestParam Integer id) {
        boolean b = employeeService.removeById(id);
        return b;
    }
}
